package cqrtplm.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.okhttp.MediaType;
import com.lark.oapi.okhttp.OkHttpClient;
import com.lark.oapi.okhttp.Request;
import com.lark.oapi.okhttp.RequestBody;
import com.lark.oapi.okhttp.Response;
import cqrtplm.entity.TestMappingDO;
import cqrtplm.mapper.TestMappingMapper;
import cqrtplm.service.TestMappingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * Description xxx
 *
 * @auther: xxx
 * @date: xxx
 */
@Slf4j
@Service
public class TestMappingServiceImpl implements TestMappingService {

    @Resource
    private TestMappingMapper testMappingMapper;

    @Override
    public TestMappingDO testFunc() {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("MaterialCode", "R210MR000QG-XDD301,RYC4002000-0V00000,R500DV200Q0V-BAR01,R210MT000Q0B-SAS01");
        jsonObject.put("OrderType ", "");
        jsonObject.put("ItemType", "");
        jsonObject.put("Factory", "");
        String json = jsonObject.toJSONString();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, json);
        Request request = new Request.Builder()
                .url("http://192.168.102.2:7002/RatoDataApi/CrmApi/GetCRMOrderList")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        try {
            Response response = client.newCall(request).execute();
            String string = response.body().string();
            log.info( "返回结果 ：：： {}",string);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return testMappingMapper.selectOne(new TestMappingDO());
    }

}